Imports RIBS.BusinessLogicLayer

Namespace DataAccessLayer

    Public MustInherit Class DataAccessLayerBaseClass
        '** PRIVATE FIELDS **

        Private _connectionString As String

        '** PROPERTIES **

        'Public ReadOnly Property DataBaseFileAndPath() As String
        '    'Get
        '    '    Dim lConnectionString() As String = Split(ConnectionString(), ";")
        '    '    For Each str As String In lConnectionString
        '    '        If InStr(str.ToUpper, ".MDB") > 0 Then
        '    '            Return Replace(str, "Sourse=", "")
        '    '            Beep()
        '    '            Exit For
        '    '        End If
        '    '    Next

        '    'End Get
        'End Property

        Public Property ConnectionString() As String
            Get
                Dim str As String = My.Settings.ConnectionString
                If str Is Nothing OrElse str.Length <= 0 Then
                    Throw New ApplicationException("ConnectionString configuration is missing from you web.config. It should contain  <appSettings><add key=""ConnectionString"" value=""database=IssueTrackerStarterKit;server=localhost;Trusted_Connection=true"" /></appSettings> ")
                Else
                    Dim AvailDbs As String = My.Settings.AvailableDatabases                    
                    str = Microsoft.VisualBasic.Replace(My.Settings.ConnectionString, "[DATABASE]", AvailDbs, , , CompareMethod.Binary)
                    Return str
                End If
            End Get
            Set(ByVal value As String)
                _connectionString = value
            End Set
        End Property

        '** Abstract Properties **

        Public MustOverride ReadOnly Property SupportsProjectCloning() As Boolean

        '*********************************************************************
        '
        ' GenerateCollectionFromReader Delegate
        '
        ' The GenerateCollectionFromReader delegate represents any method
        ' which returns a collection from a SQL Data Reader.
        '
        '*********************************************************************
        Delegate Function GenerateCollectionFromReader(ByVal returnData As IDataReader) As CollectionBase

        '
        Public MustOverride Function BackUpDataBase() As Boolean
        Public MustOverride Function GetRibsItems(ByVal issueId As Integer) As LetterSentCollection

        Public MustOverride Function GetUserWorkByDateAndAction(ByVal User As String, _
                                                                ByVal tblActions As DataTable, _
                                                                ByVal FromDate As DateTime, _
                                                                ByVal ToDate As DateTime) As DataTable

        Public MustOverride Function GetUserWorkByDateAndContactMethod(ByVal UserID As String, _
                                                                ByVal tblActions As DataTable, _
                                                                ByVal FromDate As DateTime, _
                                                                ByVal ToDate As DateTime, _
                                                                Optional ByVal UserBased As Boolean = True) As DataTable

        Public MustOverride Function GetUserWorkByDateAndSystem(ByVal UserID As String, _
                                                                ByVal tblActions As DataTable, _
                                                                ByVal FromDate As DateTime, _
                                                                ByVal ToDate As DateTime) As DataTable

        Public MustOverride Function GetActions(Optional ByVal bClosed As Boolean = False) As DataTable

        Public MustOverride Function GetUsers(Optional ByVal HideAdmin As Boolean = False) As DataTable

        Public MustOverride Function GetUserWorkLoadByDay(ByVal UserID As String, _
                                                            ByVal EffDate As DateTime) As DataTable

        Public MustOverride Function AddNewManual() As Int32

        Public MustOverride Function InsertNewAction(ByVal RibsID As Int32, _
                                                    ByVal Action As String, _
                                                    ByVal Note As String, _
                                                    ByVal ActionDate As Date, _
                                                    ByVal ContactMethod As String, _
                                                    ByVal Status As String, _
                                                    ByVal Reason As String, _
                                                    ByVal lUser As String) As Int32

        Public MustOverride Function AllocateItem(ByVal RibsID As Int32) As Boolean

        Public MustOverride Function GetUserProperties(ByVal UserID As String) As DataTable

        Public MustOverride Function SaveUserProperties(ByVal dt As DataTable) As DataTable

        Public MustOverride Function GetDailySummaryReport(ByVal FromDate As DateTime, ByVal Status As String) As DataTable

        Public MustOverride Function GetContactMethods(Optional ByVal bClosed As Boolean = False) As DataTable

        Protected Function GenerateLetterSentCollectionFromReader(ByVal returnData As IDataReader) As CollectionBase
            Dim cmtCollection As New LetterSentCollection
            While returnData.Read()
                Dim newLetterSent As New LetterSent(CInt(returnData("RibsID")), _
                                                    returnData("RECORD_ID").ToString, _
                                                     returnData("LETTER_CODE").ToString, _
                                                     returnData("CURRENT_RUN_NUMBER").ToString, _
                                                     returnData("Account_SYSTEM").ToString, _
                                                     returnData("AMOUNT_DUE").ToString, _
                                                     returnData("POLICY_NUMBER").ToString, _
                                                     returnData("PRODUCT_TYPE").ToString, _
                                                     returnData("MAILING_NAME").ToString, _
                                                     returnData("MAILING_ADDRESS_1").ToString, _
                                                     returnData("MAILING_ADDRESS_2").ToString, _
                                                     returnData("MAILING_ADDRESS_3").ToString, _
                                                     returnData("MAILING_SUBURB").ToString, _
                                                     returnData("MAILING_STATE").ToString, _
                                                     returnData("MAILING_COUNTRY").ToString, _
                                                     returnData("MAILING_POSTCODE").ToString, _
                                                     returnData("ADVISOR_FORENAME").ToString, _
                                                     returnData("ADVISER_SURNAME").ToString, _
                                                     returnData("ADVISER_AGENT_NUMBER").ToString, _
                                                     returnData("ADVISER_CLIENT_NUMBER").ToString, _
                                                     returnData("ADVISER_EMAIL_ADDRESS").ToString, _
                                                     returnData("ADVISER_PHONE_NUMBER").ToString, _
                                                     returnData("LETTER_DATE").ToString, _
                                                     returnData("DUE_DATE").ToString, _
                                                     returnData("EXCEPTION_IDENTIFIER").ToString, _
                                                     returnData("NEW_PREMIUM_AMOUNT").ToString, _
                                                     returnData("SUPERANNUATION_INDICATOR").ToString, _
                                                     returnData("PAYMENT_FREQUENCY").ToString, _
                                                     returnData("Retained").ToString, _
                                                     returnData("WriteOff").ToString, _
                                                     returnData("ManuallyAdded").ToString, _
                                                     returnData("UserID").ToString, _
                                                     returnData("CURRENT_PREMIUM_AMOUNT").ToString)
                cmtCollection.Add(newLetterSent)
            End While
            Return cmtCollection
        End Function


    End Class


End Namespace